package com.wontube.smr.remote;

import java.util.List;

import com.wontube.client.extension.utils.StringUtils;
import com.wontube.client.modle.vo.PagenateInfo;
import com.wontube.core.annotation.CacheSupport;
import com.wontube.core.annotation.NoLoginSupport;
import com.wontube.core.pub.servlet.handlers.BasicHandler;
import com.wontube.smr.bo.sites.GenreSelectBO;
import com.wontube.smr.client.ITVHandler;
import com.wontube.smr.client.model.po.Genre;
import com.wontube.smr.client.model.po.TVEpisode;
import com.wontube.smr.client.model.po.TVShow;
import com.wontube.smr.client.model.vo.EpisodeItems;
import com.wontube.smr.client.model.vo.TVShowItems;
import com.wontube.smr.dao.bo.TVSelectDao;


/**
 * @author yuechao
 * 
 */
@NoLoginSupport
public final class TVHandler extends BasicHandler implements ITVHandler {
	@Override
	@CacheSupport(timeToLiveSeconds = 12 * 7 * 3600)
	public List<Genre> selectAllGenres() {
		return GenreSelectBO.selectRemendedTVGenres();
	}
	
	@Override
	@CacheSupport(timeToLiveSeconds = 12 * 3600)
	public TVShowItems selectPopularShows(PagenateInfo pageInfo) {
		return selectPopularShows(null, pageInfo);
	}

	@Override
	@CacheSupport(timeToLiveSeconds = 12 * 3600)
	public TVShowItems selectPopularShows(String genreName, PagenateInfo pageInfo) {
		//修正Others 等重复genre
		genreName = GenreSelectBO.joinTVGenres(genreName);
		return TVSelectDao.selectHuluPopularShows(genreName, pageInfo);
	}
	
	@Override
	@CacheSupport
	public TVShowItems searchTVShows(String query, PagenateInfo pageInfo) {
		if (StringUtils.isNullOrEmpty(query)) {
			return null;
		}
		return TVSelectDao.searchHuluTVShows(query, pageInfo);
	}
	
	@Override
	@CacheSupport(timeToLiveSeconds = 6 * 3600)
	public List<TVEpisode> getEpisodeList(String showId, Integer seasonNum) {
		if (StringUtils.isNullOrEmpty(showId) || seasonNum == null || seasonNum < 1) {
			return null;
		}
		return TVSelectDao.getEpisodeList(showId, seasonNum);
	}
	
	@Override
	@CacheSupport(timeToLiveSeconds = 6 * 3600)
	public List<Integer> getAllSeasons(String showId) {
		if (StringUtils.isNullOrEmpty(showId)) {
			return null;
		}
		return TVSelectDao.getAllSeasons(showId);
	}	
	
	@Override
	@CacheSupport(timeToLiveSeconds = 6 * 3600)
	public TVShowItems selectRecentShows(PagenateInfo pageInfo) {
		return selectRecentShows(null, pageInfo);
	}
	
	@Override
	@CacheSupport(timeToLiveSeconds = 6 * 3600)
	public TVShowItems selectRecentShows(String genreName, PagenateInfo pageInfo) {
		//修正Others 等重复genre
		genreName = GenreSelectBO.joinTVGenres(genreName);
		return TVSelectDao.selectHuluRecentShows(genreName, pageInfo);
	}
	
	@Override
	@CacheSupport(timeToLiveSeconds = 6 * 3600)
	public TVShow getTVShow(String showId) {
		return TVSelectDao.getTVShow(showId);
	}
	
	@Override
	@CacheSupport(timeToLiveSeconds = 6 * 3600)
	public EpisodeItems selectPopularEpisodes(PagenateInfo pageInfo) {
		return selectPopularEpisodes(null, pageInfo);
	}

	@Override
	@CacheSupport(timeToLiveSeconds = 6 * 3600)
	public EpisodeItems selectPopularEpisodes(String genreName, PagenateInfo pageInfo) {
		//修正Others 等重复genre
		genreName = GenreSelectBO.joinTVGenres(genreName);
		return TVSelectDao.selectHuluPopularEpisodes(genreName, pageInfo);
	}

	@Override
	@CacheSupport(timeToLiveSeconds = 6 * 3600)
	public EpisodeItems selectRecentEpisodes(PagenateInfo pageInfo) {
		return selectRecentEpisodes(null, pageInfo);
	}

	@Override
	@CacheSupport(timeToLiveSeconds = 6 * 3600)
	public EpisodeItems selectRecentEpisodes(String genreName, PagenateInfo pageInfo) {
		//修正Others 等重复genre
		genreName = GenreSelectBO.joinTVGenres(genreName);
		return TVSelectDao.selectHuluRecentEpisodes(genreName, pageInfo);
	}

	@Override
	@CacheSupport
	public EpisodeItems searchEpisodes(String query, PagenateInfo pageInfo) {
		return TVSelectDao.searchHuluEpisodes(query, pageInfo);
	}

	@Override
	@CacheSupport(timeToLiveSeconds = 6 * 3600)
	public TVShowItems selectTopRatedTVShows(PagenateInfo pageInfo) {
		return selectTopRatedTVShows(null, pageInfo);
	}

	@Override
	@CacheSupport(timeToLiveSeconds = 6 * 3600)
	public TVShowItems selectTopRatedTVShows(String genreName, PagenateInfo pageInfo) {
		//修正Others 等重复genre
		genreName = GenreSelectBO.joinTVGenres(genreName);
		return TVSelectDao.selectHuluTopRatedTVShows(genreName, pageInfo);
	}

	@Override
	@CacheSupport(timeToLiveSeconds = 6 * 3600)
	public EpisodeItems selectTopRatedEpisode(PagenateInfo pageInfo) {
		return selectTopRatedEpisode(null, pageInfo);
	}

	@Override
	@CacheSupport(timeToLiveSeconds = 6 * 3600)
	public EpisodeItems selectTopRatedEpisode(String genreName, PagenateInfo pageInfo) {
		//修正Others 等重复genre
		genreName = GenreSelectBO.joinTVGenres(genreName);
		return TVSelectDao.selectHuluTopRatedEpisodes(genreName, pageInfo);
	}

	@Override
	@CacheSupport(timeToLiveSeconds = 6 * 3600)
	public TVEpisode getTVEpisode(String episodeId) {
		return TVSelectDao.getTVEpisode(episodeId);
	}
}
